

import cv2

def OnThreshold(minThres):#滑动条回调函数
  global img,thres_img #全局变量
  ret,thres_img = cv2.threshold(img,minThres,255,cv2.THRESH_BINARY)#二值化
  #cv2.circle(thres,(100,100),minThres,(0,0,255),2,cv2.LINE_AA)


img = cv2.imread('images/aaa.jpg',0) #灰度模式加载

thres_img = img.copy()#图像复制

cv2.namedWindow('image')

cv2.createTrackbar('threshold','image',50,255,OnThreshold)

OnThreshold(50)#初始调用

while(1):
  cv2.imshow('image',thres_img)
  k=cv2.waitKey(1)&0xFF
  if k==27:
    break

cv2.destroyAllWindows()
